<include file="Public:header" />
<load href="__ROOT__/css/demo_menu/jquery.treeview.css" />
<load href="__ROOT__/js/demo_menu/jquery.treeview.js" />
<script type="text/javascript">
$(function() {
        var body=$('[id=main]');  //定义根对象
        var list=$('[id=tree]'); //伸缩列表对象
        
        $("#tree").treeview({
                collapsed: true,
                animated: "medium",
                control:"#sidetreecontrol",
                persist: "location"
        });

        
        $(document).ready(function(){
            //获取并解释已经存在的父级部门分类列表
            $.getJSON(app_url+"/bumen-get_parentlist","",function(data){
                body.find('[name=tishi]').remove();
                $.each(data,function(i,c){
                    var parent_list={
                        'bm_id':c.bm_id,
                        'bm_name':c.bm_name,
                        'bm_main':c.bm_main
                    };
                  display_list(parent_list,list);
                });
            });
        });


        //父级列表显示函数
    function display_list(parent_list,hh){
        var li=$('<li></li>');
        var img=$('<img src="'+base_url+'/images/add.gif"></img>');
        var z_img=$('<img src="'+base_url+'/images/z_add.gif"></img>');
        z_img.hide();
        var ul=$('<ul></ul>');
        var href=$('<a href="'+app_url+'/user-user_list-id-'+parent_list.bm_id+'" target="bm_right"></a>').append(parent_list.bm_name);
        $.getJSON(app_url+"/bumen-get_bumenlist-id-"+parent_list.bm_id,"",function(data){
                if(data==0){
                    img.remove();
                }
            });
        href.click(function(){
            ul.empty();
            $.getJSON(app_url+"/bumen-get_bumenlist-id-"+parent_list.bm_id,"",function(data){
                if(data==0){
                    img.remove();
                }
                $.each(data,function(i,c){
                    var info_list={
                        'bm_id':c.bm_id,
                        'bm_name':c.bm_name,
                        'bm_main':c.bm_main
                    };
                    //alert(info_list.bm_name);
                    img.remove();
                    z_img.show();
                  display_bmlist(info_list,ul);
                });
            });
        });
        li.append(img).append(z_img).append(href).append(ul).appendTo(hh);
    }



        //次级列表显示函数
    function display_bmlist(parent_list,hh){
        var img=$('<img src="'+base_url+'/images/add.gif"></img>');
        var z_img=$('<img src="'+base_url+'/images/z_add.gif"></img>');
        z_img.hide();
        var tishi=$('<li></li>').append('数据加载中...请稍后...');
        var li=$('<li></li>');
        var ul=$('<ul></ul>');
        var href=$('<a href="'+app_url+'/user-user_list-id-'+parent_list.bm_id+'" target="bm_right"></a>').append(parent_list.bm_name);
        $.getJSON(app_url+"/bumen-get_bumenlist-id-"+parent_list.bm_id,"",function(data){
                if(data==0){
                    img.remove();
                }
        });
        href.click(function(){
            ul.empty();
            ul.append(tishi);
            $.getJSON(app_url+"/bumen-get_bumenlist-id-"+parent_list.bm_id,"",function(data){
                if(data==0){
                    img.remove();
                }
                $.each(data,function(i,c){
                    var info_list={
                        'bm_id':c.bm_id,
                        'bm_name':c.bm_name,
                        'bm_main':c.bm_main
                    };
                    img.remove();
                    z_img.show();
                    //alert(info_list.bm_name);
                  display_bmlist(info_list,ul);
                });
                
            });
            tishi.remove();
        });
        li.append(img).append(z_img).append(href).append(ul).appendTo(hh);
    }

    
});
</script>
<div id="main">
<div id="sidetree">
<!--    <div id="sidetreecontrol">&nbsp;<a href="?#">关闭所有</a> | <a href="?#">展开所有</a></div>-->
<ul id="tree">
    {$list}
	<li name="tishi">
            数据加载中...请稍后...
	</li>
</ul>
</div>

</div>
</body>
</html>
